<%--
  Created by IntelliJ IDEA.
  User: mabo
  Date: 2010-2-9
  Time: 9:51:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/template/common/include/top.jsp"%>

<html>
<head>
<title>Simple jsp page</title>
<script language="javascript" src="${path}/Hr/SendMail/Api.js"></script>
<script type="text/javascript">Ext.Direct.addProvider(Hr.SendMail.REMOTING_API);</script>
<script language="javascript" src="${path}/jscore/hr/hrconfig/sendMail.js"></script>
<script language="javascript" src="${path}/ext/examples/ux/Spotlight.js"></script>

<script type="text/javascript">

function openEditWin(id) {
    var jl_win = new Ext.Window({
        title:'编辑简历',
        width:650,
        height:390,
        //closeAction:'hide',//偏移出屏幕，而不从DOM树中移除窗体
        resizable:false,//是否允许改变大小
        modal:true,//是否遮罩上级页面
        plain: false,//表示为渲染window body的背景为透明的背景
        layout:'fit',
        items:[
            new Ext.FormPanel({
                id:'jl_FormPanel',
                labelWidth: 75, // label settings here cascade unless overridden
                url:path + '/hr/hrconfig.x?op=saveJlByExt',
                frame:true,
                header:false,
                bodyStyle:'padding:5px 5px 0',
                loadMask:{msg:'数据加载中。。。'},
                layout:'fit',
                items: [
                    new Ext.form.TextArea({
                        id:'hc_cl_input',
                        name:'hc.coverLetter'
                    }),
                    new Ext.form.Hidden({
                        name:'hc.id',
                        value:id
                    })
                ],
                buttons:[
                    {
                        text:'保存',
                        onClick:function() {

                            //加载动画，'edit_form'为遮盖对象
                            var mask = new Ext.LoadMask('jl_FormPanel', {
                                msg:'数据提交中'
                            });
                            mask.show();

                            Ext.getCmp('jl_FormPanel').getForm().submit({
                                success:function(myform, action)
                                {
                                    Ext.Msg.alert('消息', action.result.msg);
                                    mask.hide();
                                },
                                failure:function(myform, action)
                                {
                                    if (myform.isValid()) {
                                        Ext.Msg.alert('消息', action.result.msg);
                                    } else {
                                        Ext.Msg.alert('消息', '输入项有错误，未通过验证');
                                    }
                                    mask.hide();
                                }
                            });
                        }

                    },
                    {
                        text:'关闭',
                        onClick:function() {
                            jl_win.close();
                        }
                    }
                ]
            })
        ]
    }).show();

    var mask = new Ext.LoadMask('jl_FormPanel', {
        msg:'数据加载中'
    });
    mask.show();
    var par = {};
    par['hc.id'] = id;
    Ext.Ajax.request({
        url:path + '/hr/hrconfig.x?op=findHcClByExt',
        method:'POST',
        params:par,
        success:function(response, options) {
            maks.hide();
            Ext.getCmp('hc_cl_input').setValue(response.responseText);
        }
    });

}

Ext.onReady(function() {

    var sm = new Ext.grid.CheckboxSelectionModel();
    var cm = new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),//自动行号,
        sm,
        {
            header:'配置名称',
            dataIndex:'col1',
            width:150,
            fixed:true
        },
        {
            header:'网站名称',
            dataIndex:'col2' ,
            width:150,
            fixed:true
        },
        {
            header:'职位总数',
            dataIndex:'col3',
            width:65,
            fixed:true
        },
        {
            header:'待选无Email',
            dataIndex:'col4',
            width:80,
            fixed:true,
            renderer:function(value, cellmeta, record, rowIndex, columnIndex, store) {
                return '<a href="' + path + '/hr/zhaopin.x?op=toPage&f(hrConfig)=' + record.get('id') + '&tags=notMail">' + value + '</a>';
            }
        },
        {
            header:'待选有Email',
            dataIndex:'col5',
            width:80,
            fixed:true,
            renderer:function(value, cellmeta, record, rowIndex, columnIndex, store) {
                return '<a href="' + path + '/hr/zhaopin.x?op=toPage&f(hrConfig)=' + record.get('id') + '">' + value + '</a>';
            }
        },
        {
            header:'待发送数',
            dataIndex:'col6',
            width:65,
            fixed:true
        },
        {
            header:'已发送数',
            dataIndex:'col7',
            width:65,
            fixed:true
        },
        {
            header:'已放弃数',
            dataIndex:'col8',
            width:65,
            fixed:true
        },
        {
            header:'操作',
            dataIndex:'col8',
            renderer:function(value, cellmeta, record, rowIndex, columnIndex, store) {
                //"<a href='" + path + "/hr/zhaopin.x?op=toPage&f(hrConfig)=" + record.get('id') + "'>[浏览]</a>&nbsp;&nbsp;&nbsp;" +
                return "<a href='" + path + "/hr/hrconfig.x?op=loadData&hc.id=" + record.get('id') + "&callPage=new'> [抓取]</a>&nbsp;&nbsp;&nbsp;" +
                       "<a href='javascript:void(0)' onclick='openEditWin(\"" + record.get('id') + "\");'>[简历]</a>&nbsp;&nbsp;&nbsp;" +
                    //"<a href='" + path + "/hr/sendemail.x?op=sendEmailByExt&hc.id=" + record.get('id') + "' target='_blank'>[发送]</a>"
                       "<a href='javascript:void(0)' onclick='sendMail(\"" + record.get('id') + "\");' >[发送]</a>"
            },
            width:150,
            fixed:true
        }
    ]);
    cm.defaultSortable = true;

    // ArrayReader
    var ds = new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({url:path + '/hr/hrconfig.x?op=findListByExt'}),
        reader:new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
        }, [
            {
                name: 'id'
            },
            {
                name: 'col1'
            },
            {
                name: 'col2'
            },
            {
                name: 'col3'
            },
            {
                name: 'col4'
            },
            {
                name: 'col5'
            },
            {
                name: 'col6'
            },
            {
                name: 'col7'
            },
            {
                name: 'col8'
            }
        ])
    });
    ds.load({params:{start:0,limit:15,ps:0}});


    /*var pag = new Ext.PagingToolbar({
     id:'pag',
     pageSize: 15,
     store: ds,
     displayInfo: true,
     displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
     emptyMsg: "没有记录"
     });

     pag.addListener('beforechange', function(pt, o, e) {
     o['pagesize'] = pt.pageSize;
     o['pageno'] = Math.ceil((o['start'] + pt.pageSize) / pt.pageSize);
     ds.load({params:o});
     return false;
     });*/

    var grid = new Ext.grid.GridPanel({
        id:'grid_1',
        title:'grid',
        ds: ds,
        cm: cm,
        sm:sm,
        header:false,
        //viewConfig: {forceFit:true},
        //bbar:pag,
        loadMask:{msg:'数据加载中。。。'}
    });

    grid.addListener('cellclick', cellclick);
    function cellclick(grid, rowIndex, columnIndex, e) {
        /*var record = grid.getStore().getAt(rowIndex);   //Get the Record
         //var fieldName = grid.getColumnModel().getDataIndex(columnIndex);  //Get field name
         var data = record.get('jobDesc');
         Ext.getDom('div_jobDesc').innerHTML = data;
         Ext.getCmp('ppp4').setTitle(record.get('jobName'));
         //Ext.MessageBox.alert('show', '当前选中的数据是' + data);

         var o = {};
         o['h.companyName'] = record.get('companyName');
         jobDs.load({params:o});*/
    }

    ;


    new Ext.Viewport({
        layout:'border',
        style:'background-color:#ffffff;',
        items:[
            new Ext.Panel({
                region:'center',
                header:false,
                margins:'5 5 5 5',
                border:false,
                items:[grid],
                layout:'fit'
            }),
            /*{
             region:'center',
             margins:'5 5 5 5',
             html:'asdfasdf'
             },*/
            new Ext.Toolbar({
                region:'north',
                height: 25,
                margins:'5 5 0 5',
                items: [
                    '->',//右对齐
                    new Ext.Button({
                        text:'添加',
                        onClick:function(but, e) {
                            var win = new Ext.Window({
                                id:'edit_win',
                                width:350,
                                height:200,
                                closeAction:'hide',
                                title:'添加配置',
                                resizable:false,//是否允许改变大小
                                modal:true,//是否遮罩上级页面
                                plain: false,//表示为渲染window body的背景为透明的背景
                                layout:'fit',
                                items:[
                                    new Ext.FormPanel({
                                        id:'edit_form',
                                        labelWidth: 75, // label settings here cascade unless overridden
                                        url:path + '/hr/hrconfig.x?op=saveByExt',
                                        frame:true,
                                        header:false,
                                        bodyStyle:'padding:5px 5px 0',
                                        width: 350,
                                        defaults: {width: 230},
                                        defaultType: 'textfield',
                                        loadMask:{msg:'数据提交中'},
                                        items: [
                                            {
                                                fieldLabel: '配置名称',
                                                name: 'hc.name',
                                                allowBlank:false
                                            },
                                            {
                                                fieldLabel: 'URL地址',
                                                name: 'hc.uri',
                                                allowBlank:false
                                            },
                                            new Ext.form.ComboBox({
                                                store: new Ext.data.SimpleStore({
                                                    fields: ['hrWebName'],
                                                    data: [
                                                        ['智联招聘'],
                                                        ['中华英才'],
                                                        ['51JOB']
                                                    ]
                                                }),
                                                mode: 'local',
                                                valueField: "hrWebName",//取值列
                                                displayField: "hrWebName",//默认数据
                                                blankText: '选择抓取网站',//初始化信息
                                                emptyText: '选择抓取网站',//出错时显示信息
                                                value:'智联招聘',
                                                editable: false,
                                                allowBlank: true,
                                                forceSelection: true,
                                                triggerAction: 'all',
                                                fieldLabel: '抓取网站',
                                                name: 'hc.hrWebName',
                                                width: 80
                                            })
                                        ]
                                    })],
                                buttons: [
                                    {
                                        id:'save_but',
                                        text: '保存',
                                        onClick:function() {
                                            this.setDisabled(true);//设置成不可用

                                            //加载动画，'edit_form'为遮盖对象
                                            var mask = new Ext.LoadMask('edit_form', {
                                                msg:'数据提交中'
                                            });
                                            mask.show();

                                            Ext.getCmp('edit_form').getForm().submit({
                                                success:function(myform, action)
                                                {
                                                    //Ext.Msg.alert('消息', action.result.msg);
                                                    ds.load({params:{start:0,limit:15,ps:0}});
                                                    win.close();
                                                },
                                                failure:function(myform, action)
                                                {
                                                    if (myform.isValid()) {
                                                        Ext.Msg.alert('消息', action.result.msg);
                                                    } else {
                                                        Ext.Msg.alert('消息', '输入项有错误，未通过验证');
                                                    }

                                                    Ext.getCmp('save_but').setDisabled(false);
                                                    mask.hide();
                                                }
                                            });
                                        }
                                    },
                                    {
                                        text: '关闭',
                                        onClick:function() {
                                            Ext.getCmp('edit_win').close();
                                        }
                                    }
                                ]
                            });
                            win.show();
                        }
                    }),
                    '-',//分割线
                    new Ext.Button({
                        text:'删除',
                        onClick:function() {
                            var records = grid.getSelectionModel().getSelections();

                            var par = {};
                            if (records.length > 0) {
                                h_id = ""
                                        for (var i = 0; i < records.length; i += 1)
                                {
                                    h_id = h_id + records[i].get('id');
                                    if (i < records.length - 1) {
                                        h_id = h_id + ";"
                                    }
                                }
                                par['ids'] = h_id;
                            }

                            Ext.Ajax.request({
                                url:path + '/hr/hrconfig.x?op=delByExt',
                                method:'POST',
                                params:par,
                                success:function(response, options) {
                                    ds.load();
                                }
                            });
                        }
                    })
                    /*{
                     // xtype: 'button', // default for Toolbars, same as 'tbbutton'
                     text: 'Button'
                     },
                     {
                     xtype: 'splitbutton', // same as 'tbsplitbutton'
                     text: 'Split Button'
                     },
                     // begin using the right-justified button container
                     '->',
                     // same as {xtype: 'tbfill'}, // Ext.Toolbar.Fill
                     {
                     xtype: 'textfield',
                     name: 'field1',
                     emptyText: 'enter search term'
                     },
                     // add a vertical separator bar between toolbar items
                     '-',
                     // same as {xtype: 'tbseparator'} to create Ext.Toolbar.Separator
                     'text 1',
                     // same as {xtype: 'tbtext', text: 'text1'} to create Ext.Toolbar.TextItem
                     {xtype: 'tbspacer'},
                     // same as ' ' to create Ext.Toolbar.Spacer
                     'text 2',
                     {xtype: 'tbspacer', width: 50},
                     // add a 50px space
                     'text 3'*/
                ]
            })
        ]
    });
});
</script>

</head>
<body>
</body>
</html>